package org.rcy.framework.api.cacheable;

import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

/**
 * @author 吴康桥
 * @Description
 * @date 2022/10/8 13:51
 */


public class AbstractCache<T> implements CacheTemplate<T>{

	protected  CacheProvider provider;

	public AbstractCache(CacheProvider provider) {
		this.provider = provider;
	}

	protected CacheTemplate<T> getDelegate() {
		return this.provider.getCacheClient();
	}

	@Override
	public T get(String key) {
		return this.getDelegate().get(key);
	}

	@Override
	public T get(String key, int seconds) {
		T t = this.getDelegate().get(key);
		if (t != null) {
			this.getDelegate().touch(key, seconds);
		}
		return t;
	}
	@Override
	public boolean touch(String key, int seconds) {
		return this.getDelegate().touch(key, seconds);
	}

	@Override
	public boolean add(String key, T data) {
		return this.getDelegate().add(key, data);
	}

	@Override
	public boolean add(String key, T data, int seconds) {
		return this.getDelegate().add(key, data,seconds);
	}

	@Override
	public boolean deferred(String key, int expireTime, TimeUnit unit) {
		return this.getDelegate().deferred(key,expireTime,unit);
	}

	@Override
	public boolean set(String key, T data) {
		return this.getDelegate().set(key, data);
	}

	@Override
	public boolean set(String key, T data, int seconds) {
		return this.getDelegate().set(key, data,seconds);
	}

	@Override
	public boolean delete(String key) {
		return this.getDelegate().delete(key);
	}

	@Override
	public boolean replace(String key, T data) {
		return this.getDelegate().replace(key, data);
	}

	@Override
	public boolean replace(String key, T data, int seconds) {
		return this.getDelegate().replace(key, data, seconds);
	}

	@Override
	public Long ttl(String key) {
		return this.getDelegate().ttl(key);
	}


	@Override
	public Set<String> keys(String key) {
		return this.getDelegate().keys(key);
	}
}
